import launch
import launch_ros
from ament_index_python.packages import get_package_share_directory  #获取功能包的路径

def generate_launch_description():
    # 动作1 - 启动其他launch
    turtlesim_launch_path = [get_package_share_directory('turtlesim'),'/launch/','multisim.launch.py']  #获取功能包的路径,然后这样拼接起来。
    action_include_launch = launch.actions.IncludeLaunchDescription(
        launch.launch_description_sources.PythonLaunchDescriptionSource(
            #ros2 launch turtlesim turtlesim.launch.py  这个是小海龟内置的launch文件
            turtlesim_launch_path
        )
    )

    # 动作2 - 打印数据
    action_log_info = launch.actions.LogInfo(
        str(turtlesim_launch_path)
    )

    # 动作3 - 执行进程, 其实就是执行一个命令行, ros2 topic list 
    action_topic_list = launch.actions.ExecuteProcess(
        cmd=['ros2','topic','list']
    )

    # 动作4 - 组织动作成组,把多个动作放到一起
    action_group = launch.actions.GroupAction(
        #动作5 - 定时器
        launch.actions.TimerAction(
            period=2.0,
            actions=[
                action_include_launch
            ]
        ),
        launch.actions.TimerAction(
            period=4.0,
            actions=[
                action_topic_list
            ]
        ),
    )

    return launch.LaunchDescription([
        #action 动作
        action_log_info,
        action_group
    ])